import { build } from 'esbuild'
import progress from 'esbuild-plugin-progress'
import { esbuildPluginFileSize } from 'esbuild-plugin-filesize'
import moduleMaps from './modules.js'

;(async () => {
  await build({
    entryPoints: ['src/index.ts'],
    bundle: true,
    format: 'esm',
    outfile: 'dist/fe-utils.esm.js',
    treeShaking: true,
    tsconfig: 'tsconfig.json',
    plugins: [
      progress(),
      esbuildPluginFileSize()
    ]
  })

  await build({
    entryPoints: ['src/index.ts'],
    bundle: true,
    format: 'cjs',
    outfile: 'dist/fe-utils.cjs.js',
    treeShaking: true,
    tsconfig: 'tsconfig.json',
    plugins: [
      progress(),
      esbuildPluginFileSize()
    ]
  })

  await build({
    entryPoints: ['src/index.ts'],
    bundle: true,
    format: 'iife',
    globalName: 'feUtils',
    outfile: 'dist/fe-utils.browser.js',
    treeShaking: true,
    tsconfig: 'tsconfig.json',
    plugins: [
      progress(),
      esbuildPluginFileSize()
    ]
  })

  await build({
    entryPoints: moduleMaps,
    bundle: true,
    format: 'esm',
    outdir: 'dist/modules',
    treeShaking: true,
    tsconfig: 'tsconfig.json',
    plugins: [
      progress()
    ]
  })
})()

